import { FormItemProps } from 'antd/lib/form';
import { FormProps } from 'antd/lib/form/Form';
import { FunctionComponent } from 'react';
import { FormModel } from './model/form.model';

export interface FormScheme extends FormProps {
  properties?: FormItemScheme[];
  required?: string[];
}

export interface FormItemScheme extends FormItemProps {
  render?: FunctionComponent<SchemeItem>;
  oneOf?: Condition<boolean>;
  allOf?: Condition<boolean>;
  watchProps?: Condition;
  watchItemProps?: Condition;
  namePath?: string[];
  root?: FormModel;
  properties?: FormItemScheme[];
  type?: DataType;
  widget?: WidgetType;
  props?: any;
}

export type Condition<T = any> = { [path: string]: (value: any) => Promise<T> };

export type WidgetType =
  | 'object'
  | 'input'
  | 'inputNumber'
  | 'radioGroup'
  | 'select'
  | 'datePicker'
  | 'rangePicker'
  | 'switch';

export type DataType = 'object' | 'string' | 'number' | 'boolean' | 'array';

export interface SchemeItem {
  value?: any;
  onChange?: (value?: any, args?: any) => void;
}
